package mysql

import "gorm.io/gorm"

type Course struct {
	gorm.Model
	Name     string  `gorm:"type:varchar(20);not null;comment:课程名称"`
	Teacher  string  `gorm:"type:varchar(10);not null;comment:教师"`
	Intro    string  `gorm:"type:varchar(25);not null;comment:简介"`
	Price    float64 `gorm:"type:decimal(10,2);not null;comment:课程价格"`
	Cover    string  `gorm:"type:varchar(255);not null;comment:课程封面"`
	Video    string  `gorm:"type:varchar(255);not null;comment:课程视频"`
	StatusId int     `gorm:"type:int(1);default:1;comment:分类ID"`
}
type Status struct {
	gorm.Model
	Status int `gorm:"type:int(1);default:1;comment:分类ID 1-上架 2-未上架"`
}

func (c *Course) Add() error {
	return DB.Create(&c).Error
}
func (s *Status) GetStatusId() error {
	return DB.Where("status = ?", 1).Limit(1).Find(&s).Error
}

func (c *Course) CourseList() (course []Course, err error) {
	err = DB.Where("status_id = ?", 1).Order("price desc").Limit(5).Find(&course).Error
	return course, err
}
func (c *Course) CourseShow(courseId int) error {
	return DB.Where("id = ?", courseId).Limit(1).Find(&c).Error
}

func (c *Course) GetCourseStatusId() error {
	return DB.Where("status_id = ?", 1).Limit(1).Find(&c).Error
}
